package com.example.pictureview;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

import com.example.pictureview.utils.ActivityContext;
import com.example.pictureview.utils.PermissionsCheckUtils;

import static com.example.pictureview.utils.PermissionsCheckUtils.REQUEST_9_IMAGE;
import static com.example.pictureview.utils.PermissionsCheckUtils.REQUEST_IMAGE;
import static com.example.pictureview.utils.PermissionsCheckUtils.REQUEST_VIDEO;

public class MainActivity extends Activity implements ActivityContext {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.video_thumbnail).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!PermissionsCheckUtils.lackAndRequestPermissions(MainActivity.this, REQUEST_VIDEO, PermissionsCheckUtils.STORAGE_PERMISSIONS)) {
                    VideoThumbnailActivity.gotoActivity(MainActivity.this);
                }
            }
        });

        findViewById(R.id.image_browse).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!PermissionsCheckUtils.lackAndRequestPermissions(MainActivity.this, REQUEST_IMAGE, PermissionsCheckUtils.STORAGE_PERMISSIONS)) {
                    ImageBrowseActivity.gotoActivity(MainActivity.this);
                }

            }
        });findViewById(R.id.image_9_browse).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!PermissionsCheckUtils.lackAndRequestPermissions(MainActivity.this, REQUEST_9_IMAGE, PermissionsCheckUtils.STORAGE_PERMISSIONS)) {
                    Image9BrowseActivity.gotoActivity(MainActivity.this);
                }

            }
        });

    }


    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        switch (requestCode) {
            case REQUEST_VIDEO:
                if (PermissionsCheckUtils.hasAllPermissionsGranted(grantResults)) {
                    VideoThumbnailActivity.gotoActivity(MainActivity.this);
                }
                break;
            case REQUEST_IMAGE:
                if (PermissionsCheckUtils.hasAllPermissionsGranted(grantResults)) {
                    ImageBrowseActivity.gotoActivity(MainActivity.this);
                }
                break;
            case REQUEST_9_IMAGE:
                if (PermissionsCheckUtils.hasAllPermissionsGranted(grantResults)) {
                    Image9BrowseActivity.gotoActivity(MainActivity.this);
                }
                break;
            default:
                break;

        }

    }

    @Override
    public Activity getActivity() {
        return this;
    }
}
